<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<div class="row">
	<div class="col-md-12 col-sm-12 col-lg-12 col-xs-12 text-right">
		<t-auth:roleButton />
	</div>
</div>
<script type="text/javascript">
function addData(){
	top.openModal("/billing/billing/addDetailed?type="+"add"+"&contractId=${t_contractId}&projectId=${t_projectId}&customerId=${t_customerId}&level=${t_level}","billing_form","订单详情-添加",1100,550);
}

function editData(){
	var id=getKeyId();
	var billingState=$(".cntable.table>tbody>tr.select-tr").attr("data-billingState");
	var outStockDebt=$(".cntable.table>tbody>tr.select-tr").attr("data-outStockDebt");
	var outStockNum=$(".cntable.table>tbody>tr.select-tr").attr("data-outStockNum");
	var confirm=$(".cntable.table>tbody>tr.select-tr").attr("data-confirm");
	if(billingState=='notShipped'&& outStockDebt==outStockNum && confirm!="checked"){
		if(isEditor(id)){
			top.openModal("/billing/billing/detailed?key="+id+"&type="+"modify"+"&level=${t_level}","billing_form","订单详情-修改",1100,550);
		}
	}else{
		$.showTips("此订单不允许编辑！",1000,"warning");
	}

}

function selData(){
	var key=getKeyId();
	if(isEditor(key)){
		top.openModal("/billing/billing/detailed?key="+key+"&type="+"check","billing_form","订单详情-查看",1100,550);
	
	}
}

function deleteData(){
	 var id=getKeyId();
	 if (isEditor(id)) {
		 var url = $.getVirtualPath()+"/billing/billing/delete?key="+id;
		 deleteDataEx(url, searchCallback);
    } 
}

function exportData(){
	var url=$.getVirtualPath()+"/billing/billing/exportExcel";
	var data=$("form:first").serialize();
	var cachedId=$.getText(url,data);
	downloadExcel(cachedId);
}

function billingClose(){
	var id=getKeyId();
	if(isEditor(id)){
		var url = $.getVirtualPath()+"/billing/billing/checkBillingState?key="+id;
        var msg =  $.getText(url);
    	if("banClose"==msg){
       		$.showTips("此订单不允许关闭！",1000,"warning");
       	}else{
       		confirm("是否确认关闭订单？",function(result){
    			if(result){
    				var url = $.getVirtualPath()+"/billing/billing/closeBillingByKey";
    			    var msg =  $.getJsonPost(url,"key="+id);
    			    $.showTips(msg.message,1000,msg.resultType);
    			    formSubmit();
    			}
    		});
       	}
	}
}

/* function returnCargo(){
	var id=getKeyId();
	if(isEditor(id)){
		top.openModal("/billing/billing/returnCargoDetailed?key="+id,"billing_form","退欠货详情",1200,550);
	}
} */

function check(){
	var confirm=$(".cntable.table>tbody>tr.select-tr").attr("data-confirm");
	var id=getKeyId();
	if(confirm=="checked"){
		$.showTips("此订单已审核！",1000,"warning");
	}else{
		if(isEditor(id)){
			top.openModal("/billing/billing/checkDetailed?key="+id+"&type="+"modify","billing_form","订单详情-审核",1100,550);
		}
	}

}

//出库
function sendOutGoods(){
	var id=getKeyId();
	var confirm=$(".cntable.table>tbody>tr.select-tr").attr("data-confirm");
	if(isEditor(id)){
		console.log(confirm);
		if(confirm=="checked"){
			top.openModal("/billing/billing/sendOutGoodsDetailed?key="+id,"billing_form","发货详情",1100,550);
		}else{
			$.showTips("此订单未审核,不可发货！",1000,"warning");
		}
		
	}
}

function addPay(){
	var id=getKeyId();
	if(isEditor(id)){
		top.openModal("/billing/billing/addPayDetailed?key="+id+"&paymentState="+"pay","billing_form","付款详情",650,300);
	}
}

function printer(){
	var id=getKeyId();
	if(isEditor(id)){
		top.openModal("/billing/billing/detailedPrint?key="+id,"billing_form","付款详情",1200,550);
	}
}

function exportMaterialAll(){
	var id=getKeyId();
	if(isEditor(id)){
		var url = $.getVirtualPath()+"/billing/billing/exportDetailed?key="+id;
		window.open(url);
	}

}

</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/notifications.jsp"%>
